﻿using Qy.Core;
using SqlSugar;
using System.Threading.Tasks;

namespace Qy.Scenario;

[AppService]
public class ContentOldCmsService : QyRepository<ContentOldCms>
{
    public ContentOldCmsService( ApplicationContext applicationContext) : base(applicationContext)
    {
    }


    public async Task<PagedInfo<ContentOldCms>> PageList(ContentOldCmsQuery parm)
    {
        parm.PageSize = 20;
        var exp = Expressionable.Create<ContentOldCms>();
        exp = exp.And( content => content.Status == true);
        return await Queryable()
            .Where(exp.ToExpression())
            .WhereIF(!string.IsNullOrEmpty(parm.Title), (content) => content.Title.Contains(parm.Title))
            .OrderBy((content) => content.Id, OrderByType.Desc)
            .ToPageAsync(parm);
    }


    public async Task<ViewContentOldCms> GetOneAsync(int id)
    {
        return await Queryable()
               .LeftJoin<ContentOldCmsData>((content, data) => content.Id == data.Aid)
               .Select((content, data) => new ViewContentOldCms()
               {
                   Id = content.Id.SelectAll(),
               }, true)
               .FirstAsync(applink => applink.Id == id);

    }
}
